home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / games / ted5.zip / IGRABSRC.ZIP / XMS.BAK < prev    next >
Text File  |  1993-02-04  |  3KB  |  171 lines

  1. ////////////////////////////////////////////////////
  2. //
  3. // XMS routines
  4. //
  5. ////////////////////////////////////////////////////
  6. #include "igrab.h"
  7. #pragma hdrstop
  8.  
  9.  
  10. unsigned XMSavail;
  11. void far *XMSdriver;
  12.  
  13.  
  14. ////////////////////////////////////////////////////
  15. //
  16. // Initialize the XMS memory
  17. //
  18. ////////////////////////////////////////////////////
  19. int InitXMS(void)
  20. {
  21.  //
  22.  // See if XMS driver is present...
  23.  //
  24.  asm    mov    ax,0x4300
  25.  asm    int    0x2f
  26.  asm    cmp    al,0x80        // installed?
  27.  asm    je    Present
  28.  
  29.  return -1;
  30.  
  31.  //
  32.  // YES! We found an XMS driver! Now we
  33.  // need to get the XMS driver's entry address...
  34.  //
  35.  Present:
  36.  asm    mov    ax,0x4310
  37.  asm    int    0x2f
  38.  asm    mov    WORD PTR XMSdriver,bx
  39.  asm    mov    WORD PTR XMSdriver+2,es
  40.  
  41.  return 0;
  42. }
  43.  
  44.  
  45. ////////////////////////////////////////////////////
  46. //
  47. // Report an XMS error, if any
  48. //
  49. ////////////////////////////////////////////////////
  50. void Quit(char *string)
  51. {
  52.  _AX=3;
  53.  geninterrupt(0x10);
  54.  printf("XMS ERROR: %s\n",string);
  55.  exit(1);
  56. }
  57.  
  58. void XMSerror(void)
  59. {
  60.  if (_AX==0)
  61.    switch(_BL)
  62.    {
  63.     case 0xa0: Quit("Not enough Extended Memory available!");
  64.     case 0xa7: Quit("Invalid length!");
  65.     case 0xa2: Quit("Invalid handle!");
  66.     case 0xa3:
  67.     case 0xa4:
  68.     case 0xa5:
  69.     case 0xa6: Quit("Invalid source or dest handle/offset!");
  70.     default: Quit("Unknown XMS Memory Error!");
  71.    }
  72. }
  73.  
  74. ////////////////////////////////////////////////////
  75. //
  76. // Allocate XMS memory
  77. //
  78. ////////////////////////////////////////////////////
  79. int XMSAllocate(long size)
  80. {
  81.  unsigned rdx=(size+1023)/1024;
  82.  
  83.  asm    mov    dx,[rdx]
  84.  asm    mov    ah,9
  85.  asm    call    [ss:DWORD PTR XMSdriver]
  86.  
  87.  XMSerror();
  88.  return _DX;
  89. }
  90.  
  91. ////////////////////////////////////////////////////
  92. //
  93. // Free XMS memory
  94. //
  95. ////////////////////////////////////////////////////
  96. void XMSFreeMem(int handle)
  97. {
  98.  asm    mov  dx,[handle]
  99.  asm    mov  ah,10
  100.  asm    call [DWORD PTR XMSdriver]
  101.  XMSerror();
  102. }
  103.  
  104.  
  105. ////////////////////////////////////////////////////
  106. //
  107. // Return XMS memory available
  108. //
  109. ////////////////////////////////////////////////////
  110. unsigned XMSTotalFree(void)
  111. {
  112.  asm    mov ah,8
  113.  asm    call [DWORD PTR XMSdriver]
  114.  XMSerror();
  115.  XMSavail=_DX;
  116.  return XMSavail;
  117. }
  118.  
  119. ////////////////////////////////////////////////////
  120. //
  121. // Move XMS memory
  122. //
  123. ////////////////////////////////////////////////////
  124. struct { long bsize;
  125.      int shandle;
  126.      long soff;
  127.      int dhandle;
  128.      long doff;
  129.        } XMSparms;
  130.  
  131.  
  132. void XMSmove(int srchandle,long srcoff,int desthandle,long destoff,long size)
  133. {
  134.  unsigned DSreg,SIreg;
  135.  
  136.  //
  137.  // FOR SOME FUCKING REASON, THE NEW MS-DOS 5.0
  138.  // HIMEM.SYS DRIVER DOESN'T ACCEPT ODD XMSMOVE LENGTHS!!!
  139.  // JOHN & I SPENT 5.5 HOURS DEBUGGING THIS BULLSHIT!!
  140.  // ---- FUCK YOU MICROSOFT!!! ---- (ASSHOLES!)
  141.  //
  142.  XMSparms.bsize=(size+1)&~1;
  143.  XMSparms.shandle=srchandle;
  144.  XMSparms.dhandle=desthandle;
  145.  XMSparms.soff=srcoff;
  146.  XMSparms.doff=destoff;
  147.  
  148.  DSreg=FP_SEG(&XMSparms);
  149.  SIreg=FP_OFF(&XMSparms);
  150.  
  151.  asm    mov    si,SIreg
  152.  asm    mov    ds,DSreg
  153.  
  154.  asm    mov    ah,11
  155.  asm    call    [ss:DWORD PTR XMSdriver]
  156.  
  157.  XMSerror();
  158. }
  159.  
  160.  
  161. ////////////////////////////////////////////////////
  162. //
  163. // XMS information
  164. //
  165. ////////////////////////////////////////////////////
  166. void XMSHandleInfo(int handle)
  167. {
  168.  asm    mov   dx,[handle]
  169.  asm    mov   ah,0xe
  170.  asm    call  [DWORD PTR XMSdriver]
  171. }